package com.home.duy.GUI;

import java.awt.BorderLayout;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JInternalFrame;

import com.home.Common.Common;
import com.home.Common.Resources_Duy;
import com.home.Entity.NhanVien;
import com.home.Entity.TaiKhoan;
import com.home.duy.code.DAO.NhanVienDAO;
import com.home.duy.code.DAO.TaiKhoanDAO;
import com.home.duy.code.Model.TTTKTableModel;
import com.home.duy.code.components.ImageBackground;
import com.home.duy.code.components.ImagePanel;
import com.home.Validation.Validator;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.JobAttributes;
import java.awt.Rectangle;
import java.awt.GridBagLayout;

import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;
import javax.swing.JToolBar;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.JLabel;
import javax.swing.RowFilter;
import javax.swing.SwingConstants;

import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.font.TextAttribute;
import java.text.AttributedString;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Vector;

import javax.swing.JComboBox;
import javax.swing.JTextField;
import javax.swing.JTabbedPane;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.TableModelEvent;
import javax.swing.table.TableRowSorter;
import javax.swing.text.DefaultCaret;
import javax.swing.JPasswordField;

public class ThongTinTK extends JInternalFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final int MAX_LENGHT = 100;
	private static final int WIDTH_FORM = 800;
	private static final int HEIGHT_FORM = 570;
	private ParentFrame parent;
	private TaiKhoan taiKhoanSecleted; // @jve:decl-index=0:
	private boolean update;
	private TableRowSorter<TTTKTableModel> sorter;

	private ButtonGroup btgTinhTrang;
	private ButtonGroup btgLoaiTK;

	private JPanel jContentPane = null;
	private JPanel panelDuLieu = null;

	private JPanel panelTTChiTiet = null;

	private JScrollPane scrollPaneTable = null;

	private JTable tableData = null;

	private JTabbedPane tabbedPane = null;

	private JPanel panelThongTin = null;

	private JPanel panelDoiMatKhau = null;

	private JLabel jLabel = null;

	private JComboBox comboBoxNV = null;

	private JLabel jLabel1 = null;

	private JTextField txtTenTK = null;

	private JLabel jLabel2 = null;

	private JRadioButton rdbHoatDong = null;

	private JRadioButton rdbKhoa = null;

	private JLabel jLabel3 = null;

	private JRadioButton rdbNhanVien = null;

	private JRadioButton rdbAdmin = null;

	private JLabel jLabel4 = null;

	private JTextArea txtGhiChu = null;

	private JButton btnDongY = null;

	private JButton btnLamLai = null;

	private JLabel jLabel5 = null;

	private JLabel jLabel6 = null;

	private JPasswordField txtReMK = null;

	private JPasswordField txtMKMoi = null;

	private JButton btnDongYDoiMK = null;

	private JButton btnNhapLaiMK = null;
	private JPanel panelCommand = null;
	private JButton btnThem = null;
	private JButton btnSua = null;
	private JButton btnXoa = null;
	private JTextField txtFilter = null;
	private JLabel jLabel7 = null;
	private ImagePanel panelTT = null;
	private ImagePanel panelDMK = null;
	/**
	 * This is the xxx default constructor
	 */
	public ThongTinTK(ParentFrame parent) {
		super();
		btgTinhTrang = new ButtonGroup();
		btgLoaiTK = new ButtonGroup();
		this.parent = parent;
		initialize();
		

		EnOrDisableControl(false);
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		//this.setBounds((parent.getWidthDesktopPane()-WIDTH_FORM)/2, (parent.getHeightDesktopPane()-HEIGHT_FORM)/2, WIDTH_FORM, HEIGHT_FORM);
		this.setSize(800, 570);
		this.setContentPane(getJContentPane());
		this.setTitle(Resources_Duy.TITLE_MENU_ITEM_THONGTINTK);
		this.setClosable(true);
		this.setIconifiable(true);
	}

	// ======================== PROCESS METHOD =======================

	private Vector<NhanVien> getAllNhanVien() {
		NhanVienDAO nvDao = new NhanVienDAO();
		Vector<NhanVien> nvs = new Vector<NhanVien>();
		List<NhanVien> list = nvDao.findAll(NhanVien.class);
		for (NhanVien nv : list) {
			nvs.add(nv);
		}
		return nvs;
	}

	private void EnOrDisableControl(boolean flag) {
		jLabel.setEnabled(flag);
		jLabel1.setEnabled(flag);
		jLabel2.setEnabled(flag);
		jLabel3.setEnabled(flag);
		jLabel4.setEnabled(flag);
		comboBoxNV.setEnabled(flag);
		txtTenTK.setEnabled(flag);
		rdbHoatDong.setEnabled(flag);
		rdbKhoa.setEnabled(flag);
		rdbNhanVien.setEnabled(flag);
		rdbAdmin.setEnabled(flag);
		txtGhiChu.setEnabled(flag);
		btnDongY.setEnabled(flag);
		btnLamLai.setEnabled(flag);
		jLabel5.setEnabled(flag);
		jLabel6.setEnabled(flag);
		txtMKMoi.setEnabled(flag);
		txtReMK.setEnabled(flag);
		btnDongYDoiMK.setEnabled(flag);
		btnNhapLaiMK.setEnabled(flag);
	}

	// bat loi
	private boolean validation() {
		boolean check = true;
		if (comboBoxNV.getSelectedItem() == null) {
			check = false;
			JOptionPane.showMessageDialog(this, "Bạn Hãy Chọn Nhân Viên !",
					"Thông Báo", JOptionPane.INFORMATION_MESSAGE);
			comboBoxNV.requestFocus();
		} else if (Validator.isBlank(txtTenTK.getText())) {
			check = false;
			JOptionPane.showMessageDialog(this, "Tên Tài Khoản Không Hợp Lệ !",
					"Thông Báo", JOptionPane.INFORMATION_MESSAGE);
			txtTenTK.requestFocus();
		} else if (txtGhiChu.getText().length() > MAX_LENGHT) {
			check = false;
			JOptionPane.showMessageDialog(this,
					"Ghi Chú Đã Vượt Quá Giới Hạn !", "Thông Báo",
					JOptionPane.INFORMATION_MESSAGE);
			txtGhiChu.requestFocus();
		}

		return check;
	}

	// lay thong tin tai khoan tu tren bang dien vao text
	private void fillData(TaiKhoan tk) {
		try {
			comboBoxNV.getModel().setSelectedItem(tk);
			txtTenTK.setText(tk.getTen());
			if (tk.isTinhTrang())
				rdbHoatDong.setSelected(true);
			else
				rdbKhoa.setSelected(true);
			if (tk.isLoai())
				rdbAdmin.setSelected(true);
			else
				rdbNhanVien.setSelected(true);
			txtGhiChu.setText(tk.getGhiChu());
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage(), "Lỗi",
					JOptionPane.ERROR_MESSAGE);
		}

	}

	private void NewOrUpdateTK(TaiKhoan taiKhoan) {
		try {
			if (validation()) {
				String thongBao = "";
				String mk = "";
				TaiKhoan tk = null;
				TaiKhoanDAO tkDao = new TaiKhoanDAO();
				if (taiKhoan != null) {
					tk = taiKhoan;
					mk = taiKhoan.getMatKhau();
					thongBao = "Cập Nhật Tài Khoản Thành Công !";
				} else {
					tk = new TaiKhoan();
					tk.setMaSo(Common.getID());
					thongBao = "Thêm Tài Khoản Thành Công !";
					mk = Resources_Duy.MAT_KHAU_TAI_KHOAN_DEFAULT;
					tk.setNhanVien((NhanVien) comboBoxNV.getModel()
							.getSelectedItem());
				}
				tk.setTen(txtTenTK.getText());
				if (rdbHoatDong.isSelected())
					tk.setTinhTrang(true);
				else
					tk.setTinhTrang(false);
				if (rdbNhanVien.isSelected())
					tk.setLoai(false);
				else
					tk.setLoai(true);
				tk.setGhiChu(txtGhiChu.getText());
				tk.setMatKhau(mk);
				if (tkDao.saveOrUpdate(tk)) {
					JOptionPane.showMessageDialog(this, thongBao, "Thông Báo",
							JOptionPane.INFORMATION_MESSAGE);
					tableData.tableChanged(new TableModelEvent(tableData
							.getModel()));
					xoaField();
					EnOrDisableControl(false);
				} else
					JOptionPane
							.showMessageDialog(
									this,
									"Đã Có Lỗi Xảy Ra, Không Thể Thêm Hoặc Cập Nhật Tài Khoản !",
									"Lỗi", JOptionPane.ERROR_MESSAGE);
			}
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage(), "Lỗi",
					JOptionPane.ERROR_MESSAGE);
		}

	}

	// xoa het cac field
	private void xoaField() {
		comboBoxNV.getModel().setSelectedItem(null);
		txtTenTK.setText("");
		rdbHoatDong.setSelected(true);
		rdbNhanVien.setSelected(true);
		txtGhiChu.setText("");
		txtMKMoi.setText("");
		txtReMK.setText("");
	}

	// xu ly su kien Them
	private void processThem() {
		EnOrDisableControl(true);
		xoaField();
		taiKhoanSecleted = null;
	}

	// xu ly su kien double-click tren bang hoac Sua
	private void processSua() {
		TaiKhoanDAO tkDao = new TaiKhoanDAO();
		int index = tableData.getSelectedRow();
		taiKhoanSecleted = (TaiKhoan) tkDao.findByPk(TaiKhoan.class, Long
				.parseLong((tableData.getModel().getValueAt(index, 5))
						.toString()));
		EnOrDisableControl(true);
		fillData(taiKhoanSecleted);
	}

	// xu ly xoa tai khoan
	private void xoaTK() {
		try {
			int index = tableData.getSelectedRow();
			if (index > -1) {
				if (JOptionPane.showConfirmDialog(this,
						"Bạn Có Thực Sự Muốn Xóa Tài Khoản Này Không ?",
						"Thông Báo", JOptionPane.YES_NO_OPTION,
						JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
					TaiKhoanDAO tkDao = new TaiKhoanDAO();
					TaiKhoan tk = (TaiKhoan) tkDao.findByPk(TaiKhoan.class,
							Long.parseLong((tableData.getModel().getValueAt(
									index, 5)).toString()));
					if (!tk.isTrangThai()) {
						if (tkDao.delete(tk)) {
							JOptionPane.showMessageDialog(this,
									"Đã Xóa Thành Công tài Khoản "
											+ tk.getTen().toUpperCase(),
									"Thông Báo",
									JOptionPane.INFORMATION_MESSAGE);
							tableData.tableChanged(new TableModelEvent(
									tableData.getModel()));
						} else {
							JOptionPane
									.showMessageDialog(
											this,
											"Có Lỗi Xảy Ra, Không Thể Xóa Tài Khoản !",
											"Lỗi", JOptionPane.ERROR_MESSAGE);
						}
					} else {
						JOptionPane
								.showMessageDialog(
										this,
										"Tài Khoản Đang Trực Tuyến, Không Thể Xóa Tài Khoản !",
										"Lỗi", JOptionPane.ERROR_MESSAGE);
					}
				}
			} else
				JOptionPane.showMessageDialog(this, "Bạn Hãy Chọn Tài Khoản !",
						"Thông Báo", JOptionPane.INFORMATION_MESSAGE);
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage(), "Lỗi",
					JOptionPane.ERROR_MESSAGE);
		}

	}

	private boolean validationMK() {
		boolean check = true;
		if (Validator.isBlank(new String(txtMKMoi.getPassword()))) {
			check = false;
			JOptionPane.showMessageDialog(this, "Vui Lòng Nhập Mật Khẩu !",
					"Thông Báo", JOptionPane.INFORMATION_MESSAGE);
			txtMKMoi.requestFocus();
		} else if (Validator.isBlank(new String(txtReMK.getPassword()))) {
			check = false;
			JOptionPane.showMessageDialog(this,
					"Vui Lòng Nhập Lại Mật Khẩu Một Lần Nữa !", "Thông Báo",
					JOptionPane.INFORMATION_MESSAGE);
			txtReMK.requestFocus();
		} else if (Validator.isNotDuplicate(new String(txtMKMoi.getPassword()),
				new String(txtReMK.getPassword()))) {
			check = false;
			JOptionPane.showMessageDialog(this,
					"Mật Khẩu Xác Nhận Và Mật Khẩu Mới Không Giống Nhau !", "Thông Báo",
					JOptionPane.INFORMATION_MESSAGE);
		}

		return check;
	}

	// xu ly doi mat khau
	private void xuLyDoiMK() {
		try {
			if(validationMK())
			{
				TaiKhoanDAO tkDao = new TaiKhoanDAO();
				TaiKhoan tk = taiKhoanSecleted;
				tk.setMatKhau(new String(txtMKMoi.getPassword()));
				if(tkDao.saveOrUpdate(tk))
				{
					JOptionPane.showMessageDialog(this,
							"Thay Đổi Mật Khẩu Thành Công !", "Thông Báo",
							JOptionPane.INFORMATION_MESSAGE);
					xoaField();
					EnOrDisableControl(false);
				}
				else
					JOptionPane.showMessageDialog(this, "Có Lỗi Xảy Ra Không Thể Thay Đổi Mật Khẩu !", "Lỗi",
							JOptionPane.ERROR_MESSAGE);
			}
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage(), "Lỗi",
					JOptionPane.ERROR_MESSAGE);
		}
	}
	// xu ly nut nhap lai
	private void nhapLaiMK()
	{
		txtMKMoi.setText("");
		txtReMK.setText("");
		txtMKMoi.requestFocus();
	}
	
	// xu ly loc du lieu
	private void locDuLieu()
	{
		if(Validator.isNotBlank(txtFilter.getText()))
			sorter.setRowFilter(RowFilter.regexFilter(txtFilter.getText()));
		else
			sorter.setRowFilter(null);
	}

	// ======================== END PROCESS METHOD =======================

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getPanelDuLieu(), null);
			jContentPane.add(getPanelTTChiTiet(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes panelDuLieu
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getPanelDuLieu() {
		if (panelDuLieu == null) {
			panelDuLieu = new JPanel();
			panelDuLieu.setLayout(null);
			panelDuLieu.setBounds(new Rectangle(9, 16, 769, 228));
			panelDuLieu.setBorder(BorderFactory
					.createTitledBorder("Danh Sách Tài Khoản"));
			panelDuLieu.add(getScrollPaneTable(), null);
			panelDuLieu.add(getPanelCommand(), null);
		}
		return panelDuLieu;
	}

	/**
	 * This method initializes panelTTChiTiet
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getPanelTTChiTiet() {
		if (panelTTChiTiet == null) {
			panelTTChiTiet = new JPanel();
			panelTTChiTiet.setLayout(null);
			panelTTChiTiet.setBounds(new Rectangle(9, 255, 769, 276));
			panelTTChiTiet.setBorder(BorderFactory
					.createTitledBorder("Thông Tin Chi Tiết Tài Khoản"));
			panelTTChiTiet.add(getTabbedPane(), null);
		}
		return panelTTChiTiet;
	}

	/**
	 * This method initializes scrollPaneTable
	 * 
	 * @return javax.swing.JScrollPane
	 */
	private JScrollPane getScrollPaneTable() {
		if (scrollPaneTable == null) {
			scrollPaneTable = new JScrollPane();
			scrollPaneTable.setBounds(new Rectangle(16, 51, 738, 159));
			scrollPaneTable.setViewportView(getTableData());
		}
		return scrollPaneTable;
	}

	/**
	 * This method initializes tableData
	 * 
	 * @return javax.swing.JTable
	 */
	private JTable getTableData() {
		if (tableData == null) {
			tableData = new JTable();
			TTTKTableModel model = new TTTKTableModel();
			tableData.setModel(model);
				tableData.getColumnModel().getColumn(3).setPreferredWidth(20);
				tableData.getColumnModel().getColumn(4).setPreferredWidth(20);
			
			sorter = new TableRowSorter<TTTKTableModel>(model);
			tableData.setRowSorter(sorter);
			
			tableData.addMouseListener(new MouseAdapter() {
				public void mouseClicked(MouseEvent me) {
					if (me.getClickCount() == 2) {
						update = true;
						processSua();
					}
				}
			});
		}
		return tableData;
	}

	/**
	 * This method initializes tabbedPane
	 * 
	 * @return javax.swing.JTabbedPane
	 */
	private JTabbedPane getTabbedPane() {
		if (tabbedPane == null) {
			tabbedPane = new JTabbedPane();
			tabbedPane.setBounds(new Rectangle(15, 26, 738, 235));
			tabbedPane.addTab("Thông Tin", null, getPanelThongTin(), null);
			tabbedPane.addTab("Đổi Mật Khẩu", null, getPanelDoiMatKhau(), null);
		}
		return tabbedPane;
	}

	/**
	 * This method initializes panelThongTin
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getPanelThongTin() {
		if (panelThongTin == null) {
			jLabel4 = new JLabel();
			jLabel4.setText(" Ghi Chú");
			jLabel4.setFont(jLabel4.getFont().deriveFont(Font.BOLD));
			jLabel4.setBounds(new Rectangle(0, 50, 81, 25));
			jLabel3 = new JLabel();
			jLabel3.setText(" Loại Tài Khoản");
			jLabel3.setFont(jLabel3.getFont().deriveFont(Font.BOLD));
			jLabel3.setBounds(new Rectangle(354, 25, 100, 25));
			jLabel2 = new JLabel();
			jLabel2.setText(" Tình Trạng");
			jLabel2.setFont(jLabel2.getFont().deriveFont(Font.BOLD));
			jLabel2.setBounds(new Rectangle(0, 25, 75, 25));
			jLabel1 = new JLabel();
			jLabel1.setText(" Tên Tài Khoản");
			jLabel1.setFont(jLabel1.getFont().deriveFont(Font.BOLD));
			jLabel1.setBounds(new Rectangle(355, 0, 97, 25));
			jLabel = new JLabel();
			jLabel.setText(" Nhân Viên");
			jLabel.setFont(jLabel.getFont().deriveFont(Font.BOLD));
			jLabel.setBounds(new Rectangle(0, 0, 72, 25));
			panelThongTin = new JPanel();
			panelThongTin.setLayout(null);
			panelThongTin.add(getBtnDongY(), null);
			panelThongTin.add(getBtnLamLai(), null);
			panelThongTin.add(getPanelTT(), null);
		}
		return panelThongTin;
	}

	/**
	 * This method initializes panelDoiMatKhau
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getPanelDoiMatKhau() {
		if (panelDoiMatKhau == null) {
			jLabel6 = new JLabel();
			jLabel6.setText(" Xác Nhận Mật Khẩu Mới");
			jLabel6.setFont(jLabel6.getFont().deriveFont(Font.BOLD));
			jLabel6.setBounds(new Rectangle(0, 25, 155, 25));
			jLabel5 = new JLabel();
			jLabel5.setText(" Mật Khẩu Mới");
			jLabel5.setFont(jLabel5.getFont().deriveFont(Font.BOLD));
			jLabel5.setBounds(new Rectangle(0, 0, 99, 25));
			panelDoiMatKhau = new JPanel();
			panelDoiMatKhau.setLayout(null);
			panelDoiMatKhau.add(getPanelDMK(), null);
		}
		return panelDoiMatKhau;
	}

	/**
	 * This method initializes comboBoxNV
	 * 
	 * @return javax.swing.JComboBox
	 */
	private JComboBox getComboBoxNV() {
		if (comboBoxNV == null) {
			comboBoxNV = new JComboBox(getAllNhanVien());
			comboBoxNV.setSelectedItem(null);
			comboBoxNV.setBounds(new Rectangle(121, 0, 200, 25));
		}
		return comboBoxNV;
	}

	/**
	 * This method initializes txtTenTK
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getTxtTenTK() {
		if (txtTenTK == null) {
			txtTenTK = new JTextField();
			txtTenTK.setBounds(new Rectangle(475, 0, 200, 25));
		}
		return txtTenTK;
	}

	/**
	 * This method initializes rdbHoatDong
	 * 
	 * @return javax.swing.JRadioButton
	 */
	private JRadioButton getRdbHoatDong() {
		if (rdbHoatDong == null) {
			rdbHoatDong = new JRadioButton();
			rdbHoatDong.setText("Hoạt Động");
			rdbHoatDong.setBounds(new Rectangle(121, 25, 93, 25));
			btgTinhTrang.add(rdbHoatDong);
		}
		return rdbHoatDong;
	}

	/**
	 * This method initializes rdbKhoa
	 * 
	 * @return javax.swing.JRadioButton
	 */
	private JRadioButton getRdbKhoa() {
		if (rdbKhoa == null) {
			rdbKhoa = new JRadioButton();
			rdbKhoa.setText("Khóa");
			rdbKhoa.setBounds(new Rectangle(237, 25, 84, 25));
			btgTinhTrang.add(rdbKhoa);
		}
		return rdbKhoa;
	}

	/**
	 * This method initializes rdbNhanVien
	 * 
	 * @return javax.swing.JRadioButton
	 */
	private JRadioButton getRdbNhanVien() {
		if (rdbNhanVien == null) {
			rdbNhanVien = new JRadioButton();
			rdbNhanVien.setText("Nhân Viên");
			rdbNhanVien.setBounds(new Rectangle(475, 25, 84, 25));
			btgLoaiTK.add(rdbNhanVien);
		}
		return rdbNhanVien;
	}

	/**
	 * This method initializes rdbAdmin
	 * 
	 * @return javax.swing.JRadioButton
	 */
	private JRadioButton getRdbAdmin() {
		if (rdbAdmin == null) {
			rdbAdmin = new JRadioButton();
			rdbAdmin.setText("Quản trị");
			rdbAdmin.setBounds(new Rectangle(595, 25, 111, 25));
			btgLoaiTK.add(rdbAdmin);
		}
		return rdbAdmin;
	}

	/**
	 * This method initializes txtGhiChu
	 * 
	 * @return javax.swing.JTextArea
	 */
	private JTextArea getTxtGhiChu() {
		if (txtGhiChu == null) {
			txtGhiChu = new JTextArea();
			txtGhiChu.setBounds(new Rectangle(120, 50, 589, 75));
		}
		return txtGhiChu;
	}

	/**
	 * This method initializes btnDongY
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getBtnDongY() {
		if (btnDongY == null) {
			btnDongY = new JButton();
			btnDongY.setBounds(new Rectangle(13, 143, 90, 25));
			btnDongY.setText("Đồng Ý");
			btnDongY.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent arg0) {
					NewOrUpdateTK(taiKhoanSecleted);
				}
			});
		}
		return btnDongY;
	}

	/**
	 * This method initializes btnLamLai
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getBtnLamLai() {
		if (btnLamLai == null) {
			btnLamLai = new JButton();
			btnLamLai.setBounds(new Rectangle(138, 143, 90, 25));
			btnLamLai.setText("Làm Lại");
			btnLamLai.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent arg0) {
					if (taiKhoanSecleted != null) {
						comboBoxNV.getModel().setSelectedItem(
								taiKhoanSecleted.getNhanVien());
						txtTenTK.setText(taiKhoanSecleted.getTen());
						if (taiKhoanSecleted.isTinhTrang())
							rdbHoatDong.setSelected(true);
						else
							rdbKhoa.setSelected(true);
						if (taiKhoanSecleted.isLoai())
							rdbNhanVien.setSelected(true);
						else
							rdbNhanVien.setSelected(true);
						txtGhiChu.setText(taiKhoanSecleted.getGhiChu());
					} else {
						xoaField();
					}
				}
			});
		}
		return btnLamLai;
	}

	/**
	 * This method initializes txtReMK
	 * 
	 * @return javax.swing.JPasswordField
	 */
	private JPasswordField getTxtReMK() {
		if (txtReMK == null) {
			txtReMK = new JPasswordField();
			txtReMK.setBounds(new Rectangle(160, 25, 207, 25));
		}
		return txtReMK;
	}

	/**
	 * This method initializes txtMKMoi
	 * 
	 * @return javax.swing.JPasswordField
	 */
	private JPasswordField getTxtMKMoi() {
		if (txtMKMoi == null) {
			txtMKMoi = new JPasswordField();
			txtMKMoi.setBounds(new Rectangle(160, 0, 207, 25));
		}
		return txtMKMoi;
	}

	/**
	 * This method initializes btnDongYDoiMK
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getBtnDongYDoiMK() {
		if (btnDongYDoiMK == null) {
			btnDongYDoiMK = new JButton();
			btnDongYDoiMK.setText("Đổi Mật Khẩu");
			btnDongYDoiMK.setBounds(new Rectangle(25, 75, 110, 25));
			btnDongYDoiMK.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent arg0) {
					xuLyDoiMK();
					
				}
			});
		}
		return btnDongYDoiMK;
	}

	/**
	 * This method initializes btnNhapLaiMK
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getBtnNhapLaiMK() {
		if (btnNhapLaiMK == null) {
			btnNhapLaiMK = new JButton();
			btnNhapLaiMK.setText("Nhập Lại");
			btnNhapLaiMK.setBounds(new Rectangle(216, 74, 110, 25));
			btnNhapLaiMK.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent arg0) {
					nhapLaiMK();	
				}
			});
		}
		return btnNhapLaiMK;
	}

	/**
	 * This method initializes panelCommand	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getPanelCommand() {
		if (panelCommand == null) {
			jLabel7 = new JLabel();
			jLabel7.setBounds(new Rectangle(494, 1, 25, 23));
			jLabel7.setText("");
			jLabel7.setIcon(Common.getImageIcon(Resources_Duy.ICON_PATH+"filter.png"));
			panelCommand = new JPanel();
			panelCommand.setLayout(null);
			panelCommand.setBounds(new Rectangle(16, 27, 737, 26));
			
			panelCommand.add(getBtnThem(), null);
			panelCommand.add(getBtnSua(), null);
			panelCommand.add(getBtnXoa(), null);
			panelCommand.add(getTxtFilter(), null);
			panelCommand.add(jLabel7, null);
			
		}
		return panelCommand;
	}

	/**
	 * This method initializes btnThem	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBtnThem() {
		if (btnThem == null) {
			btnThem = new JButton();
			btnThem.setBounds(new Rectangle(0, 0, 90, 26));
			btnThem.setIcon(Common.getImageIcon(Resources_Duy.ICON_PATH+"add_new.png"));
			btnThem.setText("Thêm");
			btnThem.setContentAreaFilled(false);
			btnThem.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent arg0) {
					processThem();
					
				}
			});
			btnThem.addMouseListener(new MouseAdapter() {
				 public void mouseEntered(MouseEvent event)
				{
					 btnThem.setContentAreaFilled(true);
					 btnThem.setBackground(Color.getColor("#C7D3E0"));
				}
				 public void mouseExited(MouseEvent event)
				{
					 btnThem.setContentAreaFilled(false);
				}
			});
		}
		return btnThem;
	}

	/**
	 * This method initializes btnSua	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBtnSua() {
		if (btnSua == null) {
			btnSua = new JButton();
			btnSua.setBounds(new Rectangle(90, 0, 85, 26));
			btnSua.setIcon(Common.getImageIcon(Resources_Duy.ICON_PATH+"edit.png"));
			btnSua.setText("Sửa");
			btnSua.setContentAreaFilled(false);
			final ThongTinTK tt = this;
			btnSua.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent e) {
					if(tableData.getSelectedRow() > -1)
						processSua();
					else
						JOptionPane.showMessageDialog(tt, "Bạn Hãy Chọn Tài Khoản !",
								"Thông Báo", JOptionPane.INFORMATION_MESSAGE);
				}
			});
			btnSua.addMouseListener(new MouseAdapter() {
				 public void mouseEntered(MouseEvent event)
				{
					 btnSua.setContentAreaFilled(true);
					btnSua.setBackground(Color.getColor("#C7D3E0"));
				}
				 public void mouseExited(MouseEvent event)
				{
					 btnSua.setContentAreaFilled(false);
					btnSua.setBackground(null);
				}
			});
		}
		return btnSua;
	}

	/**
	 * This method initializes btnXoa	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBtnXoa() {
		if (btnXoa == null) {
			btnXoa = new JButton();
			btnXoa.setBounds(new Rectangle(175, 0, 85, 26));
			btnXoa.setIcon(Common.getImageIcon(Resources_Duy.ICON_PATH+"delete.png"));
			btnXoa.setText("Xóa");
			btnXoa.setContentAreaFilled(false);
			btnXoa.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent e) {
					xoaTK();
				}
			});
			btnXoa.addMouseListener(new MouseAdapter() {
				 public void mouseEntered(MouseEvent event)
				{
					 btnXoa.setContentAreaFilled(true);
					 btnXoa.setBackground(Color.getColor("#C7D3E0"));
				}
				 public void mouseExited(MouseEvent event)
				{
					 btnXoa.setContentAreaFilled(false);
				}
			});
		}
		return btnXoa;
	}

	/**
	 * This method initializes txtFilter	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getTxtFilter() {
		if (txtFilter == null) {
			txtFilter = new JTextField();
			txtFilter.setBounds(new Rectangle(519, 0, 217, 25));
			txtFilter.getDocument().addDocumentListener(new DocumentListener() {
				
				@Override
				public void removeUpdate(DocumentEvent arg0) {
					locDuLieu();
					
				}
				
				@Override
				public void insertUpdate(DocumentEvent arg0) {
					locDuLieu();					
				}
				
				@Override
				public void changedUpdate(DocumentEvent arg0) {
					locDuLieu();					
				}
			});
		}
		return txtFilter;
	}

	/**
	 * This method initializes panelTT	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private ImagePanel getPanelTT() {
		if (panelTT == null) {
			panelTT = new ImagePanel(Resources_Duy.IMAGE_PATH+"bgThongTinTK.png");
			panelTT.setLayout(null);
			panelTT.setBounds(new Rectangle(14, 13, 708, 125));
			Border line = BorderFactory.createLineBorder(Resources_Duy.COLOR_LINE_BORDER);
			panelTT.setBorder(line);
			panelTT.add(jLabel, null);
			panelTT.add(getComboBoxNV(), null);
			panelTT.add(jLabel1, null);
			panelTT.add(getTxtTenTK(), null);
			panelTT.add(jLabel2, null);
			panelTT.add(getRdbHoatDong(), null);
			panelTT.add(getRdbKhoa(), null);
			panelTT.add(jLabel3, null);
			panelTT.add(getRdbNhanVien(), null);
			panelTT.add(getRdbAdmin(), null);
			panelTT.add(jLabel4, null);
			panelTT.add(getTxtGhiChu(), null);
		}
		return panelTT;
	}

	/**
	 * This method initializes panelDMK	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private ImagePanel getPanelDMK() {
		if (panelDMK == null) {
			panelDMK = new ImagePanel(Resources_Duy.IMAGE_PATH+"bgDMK.png");
			panelDMK.setLayout(null);
			panelDMK.setBounds(new Rectangle(159, 44, 387, 100));
			Border line = BorderFactory.createLineBorder(Resources_Duy.COLOR_LINE_BORDER);
			panelDMK.setBorder(line);
			panelDMK.add(jLabel5, null);
			panelDMK.add(getTxtMKMoi(), null);
			panelDMK.add(jLabel6, null);
			panelDMK.add(getTxtReMK(), null);
			panelDMK.add(getBtnNhapLaiMK(), null);
			panelDMK.add(getBtnDongYDoiMK(), null);
		}
		return panelDMK;
	}

	
	


}
